<?php
require_once '../DTO/LoaiTinRaoVat.php';
require_once 'DBConnection.php';

class LoaiTinRaoVatDAO extends DBConnection{
	public function __construct(){
		parent::__construct();
	}
	
	//Lấy danh sách tất cả loại tin rao vặt
	public function getLoaiTinRaoVat(){
		$sql = "select * from loaitinraovat";
		
		$res = mysql_query($sql, $this->hDB);
		
		if(!$res){
			die("Failed getting loai tin rao vat");
		}
		
		if(mysql_num_rows($res)){
			$objs = array();
			$temp = mysql_fetch_assoc($res);
			while($temp){
				$objs[] = new LoaiTinRaoVat($temp['MaLoaiTRV'], $temp['TenLoaiTRV']);
				$temp = mysql_fetch_assoc($res);
			}
			return $objs;			
		}else{
			return null;
		}
	}
	
	//Lấy loại tin rao vặt theo mã loại tin rao vặt
	public function getLoaiTRVByMaLoaiTRV($maLoaiTRV){
		$sql = "select * from loaitinraovat where MaLoaiTRV='$maLoaiTRV'";
		
		$res = mysql_query($sql, $this->hDB);
		
		if(!$res){
			die("Failed getting loai tin rao vat");
		}
		
		if(mysql_num_rows($res)){			
			$temp = mysql_fetch_assoc($res);			
			$obj = new LoaiTinRaoVat($temp['MaLoaiTRV'], $temp['TenLoaiTRV']);					
			return $obj;
		}else{
			return null;
		}
	}
}










